Skip to main content

2.1 - Installing RL Libraries

Key Changes: This revision elevates the documentation from a simple list of commands to a professional setup guide. It introduces a "Project Dependencies" table to clearly define the role of each library, providing essential context for a developer. The installation process is framed as a formal "Setup Workflow" checklist, and a crucial note about PyTorch as the deep learning backend has been added. The verification step is also made more robust by including the library versions, which is a standard practice for ensuring a reproducible environment.


2.1 - Installing RL Libraries

To build and train a learning agent, our project requires several key libraries from the Python scientific computing ecosystem. This section outlines the dependencies and provides a step-by-step workflow for setting up a clean, isolated development environment.

Project Dependencies

Our implementation will rely on the following core packages:

LibraryRole
gymnasiumThe modern standard for defining Reinforcement Learning environments. It provides the API contract our SC2GymEnv wrapper will adhere to.
stable-baselines3A high-performance library of pre-implemented RL algorithms (like PPO). This will serve as the "brain" or Agent.
torchThe deep learning framework used by stable-baselines3 to define and train the neural network models.
tensorboardA visualization toolkit for inspecting the training process, allowing us to graph rewards and other metrics.

Setup Workflow

The installation is a three-step process designed to ensure a stable and reproducible environment.

  • Step 1: Create and activate a dedicated virtual environment.
  • Step 2: Install the required packages via pip.
  • Step 3: Verify the installation and library versions.

Step 1 - Create and Activate a Virtual Environment

This is a critical best practice to prevent dependency conflicts.

  1. Navigate to your project folder in your terminal.
  2. Create the environment (e.g., named venv):
    python -m venv venv
  3. Activate it:
    • Windows (Command Prompt / PowerShell):
      .\venv\Scripts\activate
    • macOS / Linux:
      source venv/bin/activate

Step 2 - Install Libraries via pip

With the virtual environment active, a single command will install all necessary packages.

pip install "stable-baselines3[extra]>=2.0.0"
  • Why this command?
    • stable-baselines3: Installs the core library.
    • [extra]: This is a crucial addition. It automatically pulls in gymnasium, torch, and tensorboard, satisfying all our dependencies in one step.
    • >=2.0.0: Specifies a minimum version to ensure API compatibility.

Step 3 - Verify Installation

Confirm that all packages were installed correctly and check their versions.

  1. In your active terminal, start a Python interpreter by typing python.

  2. At the Python prompt (>>>), run the following code:

    try:
    import gymnasium
    import stable_baselines3
    import torch

    print("--- Verification Successful ---")
    print(f"gymnasium version: {gymnasium.__version__}")
    print(f"stable-baselines3 version: {stable_baselines3.__version__}")
    print(f"torch version: {torch.__version__}")
    print("-----------------------------")

    except ImportError as e:
    print(f"An error occurred: {e}")
    print("Please check your installation.")

    ```If you see the version numbers without any errors, your environment is correctly configured, and you are ready to implement the `SC2GymEnv` wrapper.